package com.ruibang.glass.material.controller.warehousemanage;


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.material.constant.MaterialWareHouseCode;
import com.ruibang.glass.material.domain.req.WareHouseInfoReq;
import com.ruibang.glass.material.entity.MaterialWarehouseInfo;
import com.ruibang.glass.material.service.MaterialWarehouseInfoService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 仓库信息管理 前端控制器
 * </p>
 *
 * @author mameng
 * @since 2024-02-05
 */
@Api(tags = "仓库信息管理")
@RestController
@RequestMapping("/api/glass/material/ware/house/info")
public class WareHouseInfoController {

    @Autowired
    private MaterialWarehouseInfoService materialWarehouseInfoService;

    @PostMapping("/list")
    @ApiOperation(value = "获取仓库信息列表", response = ResultBody.class)
    public ResultBody getPageList(@RequestBody WareHouseInfoReq wareHouseInfoReq) {
        return ResultBody.success(materialWarehouseInfoService.getPage(wareHouseInfoReq));
    }

    @PostMapping("/getWareHouseList")
    @ApiOperation(value = "获取仓库信息列表(不分页)", response = ResultBody.class)
    public ResultBody getWareHouseList(@RequestBody WareHouseInfoReq wareHouseInfoReq) {
        return ResultBody.success(materialWarehouseInfoService.getWareHouseList(wareHouseInfoReq));
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody add(@RequestBody MaterialWarehouseInfo materialWarehouseInfo) {
        materialWarehouseInfoService.add(materialWarehouseInfo);
        return ResultBody.success();
    }

    @PostMapping("/removeById")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody removeById(@RequestBody MaterialWarehouseInfo materialWarehouseInfo) {
        if (CollectionUtils.isNotEmpty(materialWarehouseInfo.getIds())) {
            materialWarehouseInfoService.removeBatchByIds(materialWarehouseInfo.getIds());
        }
        if (StringUtils.isNotEmpty(materialWarehouseInfo.getId())) {
            materialWarehouseInfoService.removeById(materialWarehouseInfo.getId());
        }
        return ResultBody.success();
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "修改", response = ResultBody.class)
    public ResultBody updateById(@RequestBody MaterialWarehouseInfo materialWarehouseInfo) {
        materialWarehouseInfoService.updateById(materialWarehouseInfo);
        return ResultBody.success();
    }

    @GetMapping("/updateStatus/{id}")
    @ApiOperation(value = "修改状态", response = ResultBody.class)
    public ResultBody updateStatus(@PathVariable("id") String id) {
        materialWarehouseInfoService.updateStatus(id);
        return ResultBody.success();
    }


    @GetMapping("/getWareList")
    @ApiOperation(value = "获取下拉仓库信息", response = ResultBody.class)
    public ResultBody getWareList() {
        return ResultBody.success(materialWarehouseInfoService.getWareList());
    }


    @GetMapping("/getYCLWareList")
    @ApiOperation(value = "获取原材料下拉仓库信息", response = ResultBody.class)
    public ResultBody getYCLWareList() {
        return ResultBody.success(materialWarehouseInfoService.list(Wrappers.<MaterialWarehouseInfo>lambdaQuery()
                .eq(MaterialWarehouseInfo::getWarehouseCode, MaterialWareHouseCode.YCLK_CK.getMsg())));
    }




    @GetMapping("/getOneById/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody getOneById(@PathVariable("id") String id) {
        return ResultBody.success(materialWarehouseInfoService.getById(id));
    }


    @GetMapping("/getCheckWareHouseList")
    @ApiOperation(value = "盘点下拉带上仓库管理员", response = ResultBody.class)
    public ResultBody getCheckWareHouseList() {
        return ResultBody.success(materialWarehouseInfoService.list(
                Wrappers.<MaterialWarehouseInfo>lambdaQuery().select(MaterialWarehouseInfo::getId,MaterialWarehouseInfo::getWarehouseName,MaterialWarehouseInfo::getAdministrator)
        ));
    }


    @GetMapping("/getWareListByName/{id}")
    @ApiOperation(value = "根据厂房名获取仓库", response = ResultBody.class)
    public ResultBody getWareList(@PathVariable("id") String id ) {
        return ResultBody.success(materialWarehouseInfoService.list(
                Wrappers.<MaterialWarehouseInfo>lambdaQuery()
                        .select(MaterialWarehouseInfo::getId,MaterialWarehouseInfo::getWarehouseName)
                .eq(MaterialWarehouseInfo::getBelongToFactoryId,id)
        ));
    }


    @GetMapping("/getWarehouseByCode/{warehouseCode}")
    @ApiOperation(value = "获取厂房下拉", response = ResultBody.class)
    public ResultBody getFactorySelectList(@PathVariable("warehouseCode") String warehouseCode) {
        return ResultBody.success(materialWarehouseInfoService.list(
                Wrappers.<MaterialWarehouseInfo>lambdaQuery().select(MaterialWarehouseInfo::getId,MaterialWarehouseInfo::getWarehouseName).eq(MaterialWarehouseInfo::getWarehouseCode,warehouseCode)
        ));
    }

}
